#include "Sphere.h"

//The generic Sphere constructor
Sphere::Sphere() {
	name = "Sphere";
	positiveDiscriminant = false;
	issphere = true;
	boundingVolume = false;
}

//The initialized Sphere constructor
Sphere::Sphere(Vector3 c, float r) {
	Sphere();
	center = c;
	radius = r;
}

//Returns the normal of the sphere
Vector3 Sphere::normal(Vector3 p) {
	Vector3 n = p - center;
	n.normalize();
	
	return n;
}

//Determines the intersect of a given ray with the sphere
float Sphere::tIntersect(Vector3 p, Vector3 r, Object* obj) {
	return -1;
	Vector3 D = p - center;
	
	float discriminant = pow(Vector3::dotProduct(D, r), 2) - pow(D.length(), 2) + pow(radius, 2);
	float b = Vector3::dotProduct(D, r)*(-1);
	
	positiveDiscriminant = false;
	
	if (discriminant >= 0) {
		positiveDiscriminant = true;
		
		t1 = b + sqrt(discriminant);
		t2 = b - sqrt(discriminant);
	}
}